package cn.kgc.tangcco.pojo;

import cn.hutool.core.util.IdcardUtil;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;

import java.util.Date;

/**
 * @author 李昊哲
 * @Description
 * @create 2020/10/11 8:46
 */
@NoArgsConstructor
@Getter
@Setter
public class Emp {
    private Integer id;
    @NonNull
    private String name;
    @NonNull
    private String idCard;
    private int gender;
    @JsonFormat(pattern="yyyy-MM-dd",timezone="GMT+8")
    @JSONField(format = "yyyy-MM-dd")
    private Date birthday;
    private Integer age;

    public Emp(@NonNull String name, @NonNull String idCard) {
        this.name = name;
        this.idCard = idCard;
        this.gender = IdcardUtil.getGenderByIdCard(idCard);
        this.birthday = IdcardUtil.getBirthDate(idCard);
        this.age = IdcardUtil.getAgeByIdCard(idCard);
    }

    public Emp(Integer id, @NonNull String name, @NonNull String idCard) {
        this(name,idCard);
        this.id = id;
    }

    public void setIdCard(String idCard) {
        this.idCard = idCard;
        this.gender = IdcardUtil.getGenderByIdCard(idCard);
        this.birthday = IdcardUtil.getBirthDate(idCard);
        this.age = IdcardUtil.getAgeByIdCard(idCard);
    }
}
